<template>
  <div class="update-gender">
  <van-picker
  title="性别"
  show-toolbar
  :columns="columns"
  :default-index="value"
  @cancel="$emit('close')"
  @confirm="onConfirm"
  @change="onchangeGender"
/>
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {
  name: 'UpdateGender',
  data () {
    return {
      columns: ['男', '女'],
      loadGender: this.value
    }
  },
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  methods: {
    async onConfirm () {
      try {
        const loadGender = this.loadGender
        await updateUserProfile({
          gender: loadGender
        })
        // 更新视图
        this.$emit('input', loadGender)
        // 关系弹出()
        this.$emit('close')
        this.$toast.success('更新成功')
      } catch (err) {
        this.$toast.fail('更新失败')
      }
    },
    onchangeGender (picker, value, index) {
    //   console.log(picker, value, index)
      this.loadGender = index
    }
  }
}

</script>

<style>

</style>
